package cn.innosmart.aq.manager;


import com.tutk.p2p.ConnectionEntity;
import com.tutk.p2p.ResponseHandler;

import java.util.HashMap;

/**
 * Created by David on 2015/6/30.
 */
public class EventManager extends BaseManager {
    private String Tag = "EventManager";


    private static class EventManagerInstance {
        private static final EventManager instance = new EventManager();
    }

    public static EventManager getInstance() {
        return EventManagerInstance.instance;
    }

    private EventManager() {
    }

    // EventManager.Remove
    public boolean Remove(ConnectionEntity connectionEntity, HashMap<Long, ResponseHandler> mReqRspHashMap, String UID, String params, long callid) {
        log(Tag, "Remove. UID = " + UID + ", params = " + params);
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mEventManagerRemoveCallBack);
        mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, UID, "EventManager.Remove", params, callid)) {
            mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    private ResponseHandler.ResponseCallback mEventManagerRemoveCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity,String message) {
            log(Tag, "EventManager.Remove get response=" + message);

        }
    };

    // EventManager.Query
    public boolean Query(ConnectionEntity connectionEntity, HashMap<Long, ResponseHandler> mReqRspHashMap, String UID, String params, long callid) {
        log(Tag, "Query. UID = " + UID + ", params = " + params);
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mEventManagerQueryCallBack);
        mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, UID, "EventManager.Query", params, callid)) {
            mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    private ResponseHandler.ResponseCallback mEventManagerQueryCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity,String message) {
            log(Tag, "EventManager.Query get response=" + message);

        }
    };
}
